package com.itheima.pinda.controller;

import com.itheima.pinda.DTO.angency.AgencyScopeDto;
import com.itheima.pinda.DTO.user.CourierScopeDto;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdAgencyScopeService;
import com.itheima.pinda.service.PdCourierScopeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "业务管理")
@RestController
@RequestMapping(value = "/base/scope")
public class ScopeController {

    @Autowired
    private PdAgencyScopeService agencyScopeService;
    @Autowired
    private PdCourierScopeService courierScopeService;

    /**
     * 批量保存机构业务范围
     *
     * @param dtoList 机构业务范围信息
     * @return 返回信息
     */
    @PostMapping("/agency/batch")
    public Result batchSaveAgencyScope(@RequestBody List<AgencyScopeDto> dtoList) {
        agencyScopeService.batchSaveAgencyScope(dtoList);

        return Result.ok();
    }

    /**
     * 删除机构业务范围信息
     *
     * @param dto 参数
     * @return 返回信息
     */
    @DeleteMapping("/agency")
    public Result deleteAgencyScope(@RequestBody AgencyScopeDto dto) {
        agencyScopeService.deleteAgencyScope(dto);

        return Result.ok();
    }

    /**
     * 获取机构业务范围列表
     *
     * @param areaId   行政区域id
     * @param agencyId 机构id
     * @return 机构业务范围列表
     */
    @GetMapping("/agency")
    public List<AgencyScopeDto> findAllAgencyScope(@RequestParam(name = "areaId", required = false) String areaId,
                                                   @RequestParam(name = "agencyId", required = false) String agencyId,
                                                   @RequestParam(name = "agencyIds", required = false) List<String> agencyIds,
                                                   @RequestParam(name = "areaIds", required = false) List<String> areaIds) {
        agencyScopeService.findAllAgencyScope(areaId,agencyId,agencyIds,areaIds);
      return null;
    }

    /**
     * 批量保存快递员业务范围
     *
     * @param dtoList 快递员业务范围信息
     * @return 返回信息
     */
    @PostMapping("/courier/batch")
    public Result batchSaveCourierScope(@RequestBody List<CourierScopeDto> dtoList) {
        courierScopeService.batchSaveCourierScope(dtoList);
        return Result.ok();
    }

    /**
     * 删除快递员业务范围信息
     *
     * @param dto 参数
     * @return 返回信息
     */
    @DeleteMapping("/courier")
    public Result deleteCourierScope(@RequestBody CourierScopeDto dto) {
        courierScopeService.deleteCourierScope(dto);
        return Result.ok();
    }

    /**
     * 获取快递员业务范围列表
     *
     * @param areaId 行政区域id
     * @param userId 快递员id
     * @return 快递员业务范围列表
     */
    @GetMapping("/courier")
    public List<CourierScopeDto> findAllCourierScope(@RequestParam(name = "areaId", required = false) String areaId,
                                                     @RequestParam(name = "userId", required = false) String userId) {
        return courierScopeService.findAllCourierScope(areaId,userId);
    }

}
